#include <bits/stdc++.h>
using namespace std;
int t,n,a[200005],vis[200005];
long long Max;
int read();
void write(long long x);
void dfs(int deep);
void w();
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    t=read();

    for(int i=1;i<=t;i++){
        Max=-1;
        n=read();
        for(int j=1;j<=n;j++){
            a[j]=read();
        }
        dfs(2);
        write(Max);
        putchar('\n');
    }

    return 0;
}

int read(){
    int x,y=1;char c;
    while((c=getchar())>'9'||c<'0') if(c=='-') y=-1;
    x=(c^48);
    while((c=getchar())>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48);
    return x*y;
}

void write(long long x){
    if(x<0) x=-x,putchar('-');
    if(x>9) write(x/10);
    putchar(x%10+48);

}

void dfs(int deep){
    if(deep>n){
        w();
        return;
    }
    vis[deep]=1;
    dfs(deep+1);
    vis[deep]=0;
    dfs(deep+1);
}

void w(){
    long long ans=0;
    for(int i=1;i<=n;i++){
        int f=0;
        for(int j=i-1;j>=1;j--){
            if(vis[j]==vis[i]){
                f=j;
                break;
            }
        }
        if(f&&a[i]==a[f]){
            ans+=a[i];
        }
    }
    if(ans>Max) Max=ans;
}
